<template>
<div>
    <home-header ></home-header>
    <home-swiper :swiperList="swiperList"></home-swiper>
    <home-icons :iconList="iconList"></home-icons>
    <home-recommd :recommdList="recommdList"></home-recommd>
    <home-weekend :weekendList="weekendList"></home-weekend>
</div>
</template>

<script>
import HomeHeader from './HomeHead'
import HomeSwiper from './HomeSwiper'
import HomeIcons from './HomeIcons'
import HomeRecommd from './Recommd'
import HomeWeekend from './Weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  name: 'Home',
  components: {
    HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommd,
    HomeWeekend
  },
  data () {
    return {
      lastCity: '',
      weekendList: [],
      iconList: [],
      swiperList: [],
      recommdList: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      axios.get('./api/index.json?city=' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.weekendList = data.weekendList
        this.iconList = data.iconList
        this.swiperList = data.swiperList
        this.recommdList = data.recommdList
      }
      console.log(res)
    }
  },
  mounted () {
    this.lastCity = this.city
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.lastCity = this.city
      this.getHomeInfo()
    }
  }
}
</script>

<style scoped>

</style>
